package com.caigou.component;

import com.caigou.mapper.cms.ChannelMapper;
import com.caigou.pojo.ChannelOtherConfigData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 处理所有“列表页面”，生成网站静态列表页面
 */
@Slf4j
@Component
public class HtmlListComponent {
    @Resource
    private TemplateComponent templateComponent;

    @Resource
    private ChannelMapper channelMapper;

    /**
     * 生成资讯专题列表静态html页面
     * @return
     */
    public String buildNewsSpecialList(){
        Map<String, Object> map = new HashMap<>();
        //获取网站首页的title、keyword、description
        ChannelOtherConfigData channelOtherConfigData = channelMapper.loadChannelOtherConfig("101");
        map.put("title", channelOtherConfigData.getChannelTitle());
        map.put("keyword", channelOtherConfigData.getChannelKeyword());
        map.put("description", channelOtherConfigData.getChannelDescriptions());
        String url = null;
        try {
            url = templateComponent.createHtml("WEBSITEMAP", map);
        } catch (IOException e){
            log.error(e.getMessage(), e);
        }
        return url;
    }

    /**
     * 生成我要发布的列表静态页面
     * @return
     */
    public String buildPublishListHtml(){
        String templateCode = "PUBLISHLIST";
        Map<String, Object> map = new HashMap<String, Object>();
        // 返回生成的url
        String url = null;
        try{
            url = templateComponent.createHtml(templateCode, map);
        }catch(IOException e){
            log.error(e.getMessage(),e);
        }
        return url;
    }

}
